#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
long print_dir(char path[]){
	DIR *d;
	struct dirent *de;
	struct stat buf;
	int exists;
	long byte = 0;
	char tmp[1000];
	int n = 0;
	char dm[10];

	d = opendir(path);
	if (d == NULL) {
		perror("prsize");
		exit(1);
	}

	while( NULL!=(de = readdir(d)) ){
		n++;
		if(n%4==0){
			sprintf(dm, "%s", "\n");
		}else{
			sprintf(dm, "%s", "");
		}
		const char * cur = ".";
		const char * parent = "..";
		sprintf(tmp, "%s\\%s", path, de->d_name);
		exists = stat(tmp, &buf);
		if( strcmp(de->d_name, cur)==0 ){
			printf(".%-29s", dm);
			continue;
		}else if( strcmp(de->d_name, parent)==0 ){
			printf("..%-28s", dm);
			continue;
		}
		if (exists < 0) {
			fprintf(stderr, "Couldn't stat %s\n", tmp);
		} else {
			if( buf.st_mode & S_IFDIR ){
				printf("./%-28s%s", de->d_name, dm);
			}else{
				printf("%-30s%s", de->d_name, dm);
			}
		}
	}
	closedir(d);
	return byte;
}
int main(int argc, char** argv){
	char* paths = argc==1 ? "." : argv[1];
	print_dir( paths );
	return 0;
} 
